﻿CREATE FUNCTION [Utilities].[IsBitUnion]
(
	-- the bits to check as an integer
	@iBits INT
	-- this bits to test
	,@iTestBits INT
)
RETURNS BIT
AS
BEGIN
	DECLARE @ComparisonResults INT;

	-- bitwise and the bits and the test bits
	SET @ComparisonResults = @iBits & @iTestBits;

	-- if the input bits equals the test bits, we have a union
	IF (@ComparisonResults = @iTestBits)
		RETURN 1;

	RETURN 0;
END;